{% extends 'base.html' %}
{% load form_helpers %}
{% load helpers %}

{% block title %}{% if editing %}Editing {{ obj_type }} {{ obj }}{% else %}Add a new {{ obj_type }}{% endif %}{% endblock %}

{% block content %}
    <form id="nb-create-form" action="" method="post" enctype="multipart/form-data" class="h-100 vstack">
        {% csrf_token %}
        {% for field in form.hidden_fields %}
            {{ field }}
        {% endfor %}
        <div class="row justify-content-center align-content-start flex-fill">
            <div class="col-lg-8 col-md-10 mb-10">
                <h3>
                    {% if obj %}
                        {% with obj|get_docs_url as docs_url %}
                            {% if docs_url %}
                                <a href="{{ docs_url }}" target="_blank" class="btn btn-link btn-sm float-end" title="Help">
                                    <span aria-hidden="true" class="mdi mdi-help-circle"></span>
                                </a>
                            {% endif %}
                        {% endwith %}
                    {% endif %}
                </h3>
            </div>
            <div class="col-lg-8 col-md-10">
                {% block tabs %}{% endblock %}
                {% block form_errors %}
                    {% if form.non_field_errors or model_form.non_field_errors %}
                        <div class="card border-danger">
                            <div class="card-header bg-danger-subtle border-danger text-body">
                                <strong>Errors</strong>
                            </div>
                            <div class="card-body">
                                {{ form.non_field_errors }}
                                {{ model_form.non_field_errors }}
                            </div>
                        </div>
                    {% endif %}
                {% endblock %}
                {% block form %}
                    <div class="card">
                        <div class="card-header"><strong>{{ obj_type|capfirst }}</strong></div>
                        <div class="card-body">
                            {% block form_fields %}
                                {% render_form form %}
                            {% endblock %}
                        </div>
                    </div>
                    {% include 'inc/extras_features_edit_form_fields.html' %}
                {% endblock %}
            </div>
        </div>
        <div class="nb-form-sticky-footer">
            {% block buttons %}
                {% if editing %}
                    <button type="submit" name="_update" class="btn btn-primary">
                        <span aria-hidden="true" class="mdi mdi-check me-4"></span><!--
                        -->Update
                    </button>
                {% else %}
                    <button type="submit" name="_create" class="btn btn-primary">
                        <span aria-hidden="true" class="mdi mdi-check me-4"></span><!--
                        -->Create
                    </button>
                    <button type="submit" name="_addanother" class="btn btn-primary">
                        <span aria-hidden="true" class="mdi mdi-check me-4"></span><!--
                        -->Create and Add Another
                    </button>
                {% endif %}
                <a href="{{ return_url }}" class="btn btn-secondary">
                    <span aria-hidden="true" class="mdi mdi-close me-4"></span><!--
                    -->Cancel
                </a>
            {% endblock %}
        </div>
    </form>
{% endblock %}

{% block javascript %}
    {{ block.super }}
    {{ form.media }}
{% endblock %}
